package cn.com.dcsgo.useservlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @ClassName SimpleWebService
 * @Description 演示使用Servlet处理Get和Post请求
 * @Author Dcs
 * @LastChangeDate 2024/4/15 20:13
 * @Version v1.0
 */

public class SimpleWebService extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //处理Get请求逻辑
        resp.setContentType("text/plain");
        resp.getWriter().println("This is a Get request response");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //处理Post请求逻辑
        String data = req.getParameter("data");
        resp.setContentType("text/plain");
        resp.getWriter().println("Received Post data: " + data);
    }
}
